package com.daxt.controller.template;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daxt.common.result.Result;
import com.daxt.common.result.ResultCode;
import com.daxt.common.result.ResultUtil;
import com.daxt.mapper.sys.UreportFileMapper;
import com.daxt.model.constant.BaseConstants;
import com.daxt.model.dic.TemplateType;
import com.daxt.model.service.base.vo.UreportFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "模板管理")
@RestController
@RequestMapping("/template")
public class TemplateController {


//    @Autowired
//    private TemplateMapper templateMapper;
    @Autowired
    private UreportFileMapper ureportFileMapper;




    @ApiOperation(value = "获取列表", notes = "")
    @GetMapping("")
    public Result<List<UreportFile>> list() {

        QueryWrapper<UreportFile> queryWrapper = new QueryWrapper<UreportFile>();
        queryWrapper.notIn("isDelete",BaseConstants.DELETE_IS);
        List<UreportFile> infos = ureportFileMapper.selectList(queryWrapper);

        return ResultUtil.data(ResultCode.RESULT_SUCCESS.getCode(), "", infos);
    }


    @ApiOperation(value = "详情", notes = "")
    @GetMapping("/{id}")
    public Result<UreportFile> details(@PathVariable("id") String id) {
        UreportFile info = ureportFileMapper.selectById(id);
        return ResultUtil.success(info);
    }


    @ApiOperation(value = "删除(批量)", notes = "")
    @DeleteMapping("")
    public Result<String> delete(@RequestBody @Valid @NotEmpty List<String> ids) {

        UreportFile entity = new UreportFile();
        entity.setIsDelete(BaseConstants.DELETE_IS);
        QueryWrapper<UreportFile> qw = new QueryWrapper<>();
        qw.in("id", ids);
        ureportFileMapper.update(entity,qw);

        return ResultUtil.success();
    }



}
